package monster.com.cvh.adapter;

import android.app.Activity;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import monster.com.cvh.R;
import monster.com.cvh.activity.LoginActivity;
import monster.com.cvh.activity.UserMessagerEdtActivity;
import monster.com.cvh.bean.UserMessageInfoBean;
import monster.com.cvh.constant.Constans;
import monster.com.cvh.util.MyConstant;
import monster.com.cvh.util.SPUtils;

import static monster.com.cvh.constant.Constans.FINISH;
import static monster.com.cvh.constant.Constans.NO_DATA;
import static monster.com.cvh.constant.Constans.UNFINISH;

/**
 * @author: 13580
 * @data: 2018/3/15
 * @function: UserMessageFragment信息填写项adapter
 */

public class UserMessageFragmentAdaper extends BaseQuickAdapter<UserMessageInfoBean, BaseViewHolder> {

    public UserMessageFragmentAdaper(@Nullable List<UserMessageInfoBean> data) {
        super(R.layout.item_fragment_user_writer, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, UserMessageInfoBean item) {
        helper.setText(R.id.tv_item_fragment_title, item.getName());
        if (SPUtils.getString(mContext, MyConstant.TOKEN, "").isEmpty()) {
            helper.setText(R.id.tv_item_fragment_tips, mContext.getString(R.string.fragment_resume_no_data));
        } else {
            switch (item.getCompleteType()) {
                case NO_DATA:
                    helper.setText(R.id.tv_item_fragment_tips, mContext.getResources().getString(R.string.fragment_resume_no_data));
                    break;
                case UNFINISH:
                    helper.setText(R.id.tv_item_fragment_tips, mContext.getResources().getString(R.string.fragment_resume_un_finished));
                    break;
                case FINISH:
                    helper.setText(R.id.tv_item_fragment_tips, mContext.getResources().getString(R.string.fragment_resume_finished));
                    break;

            }
        }

        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (SPUtils.getString(mContext, "token", "").equals("")) {
                    Intent intent = new Intent(mContext, LoginActivity.class);
                    intent.putExtra(Constans.VISITOR, Constans.LOGIN_WITHOUT_OPTION);
                    ((Activity) mContext).startActivityForResult(intent, Constans.LOGIN_WITHOUT_OPTION);
                    return;
                }
                //因为adapter加入头部，所以真正开始位置是1
                switch (helper.getAdapterPosition()) {
                    case 1:
                        Intent personalInfoIntent = new Intent(mContext, UserMessagerEdtActivity.class);
                        personalInfoIntent.putExtra(Constans.USER_MSG_EDT, Constans.PERSONAL_INFO);
                        mContext.startActivity(personalInfoIntent);
                        break;
                    case 2:
                        Intent occupationIntent = new Intent(mContext, UserMessagerEdtActivity.class);
                        occupationIntent.putExtra(Constans.USER_MSG_EDT, Constans.OCCUPATION_INTENT);
                        mContext.startActivity(occupationIntent);
                        break;
                    case 3:
                        Intent educationIntent = new Intent(mContext, UserMessagerEdtActivity.class);
                        educationIntent.putExtra(Constans.USER_MSG_EDT, Constans.EDUCATION);
                        mContext.startActivity(educationIntent);
                        break;
                    case 4:
                        Intent honorCertificateIntent = new Intent(mContext, UserMessagerEdtActivity.class);
                        honorCertificateIntent.putExtra(Constans.USER_MSG_EDT, Constans.HONOR_CERTIFICATE);
                        mContext.startActivity(honorCertificateIntent);
                        break;
                    case 5:
                        Intent experienceInSchool = new Intent(mContext, UserMessagerEdtActivity.class);
                        experienceInSchool.putExtra(Constans.USER_MSG_EDT, Constans.EXPERIENCE_IN_SCHOOL);
                        mContext.startActivity(experienceInSchool);
                        break;
                    case 6:
                        Intent workExperienceIntent = new Intent(mContext, UserMessagerEdtActivity.class);
                        workExperienceIntent.putExtra(Constans.USER_MSG_EDT, Constans.WORK_EXPERIENCE);
                        mContext.startActivity(workExperienceIntent);
                        break;
                    case 7:
                        Intent professionSkillIntent = new Intent(mContext, UserMessagerEdtActivity.class);
                        professionSkillIntent.putExtra(Constans.USER_MSG_EDT, Constans.PROFESSIONAL_SKILL);
                        mContext.startActivity(professionSkillIntent);
                        break;
                    case 8:
                        Intent qualificationIntent = new Intent(mContext, UserMessagerEdtActivity.class);
                        qualificationIntent.putExtra(Constans.USER_MSG_EDT, Constans.QUALIFICATION);
                        mContext.startActivity(qualificationIntent);
                        break;
                    case 9:
                        Intent projectExperienceIntent = new Intent(mContext, UserMessagerEdtActivity.class);
                        projectExperienceIntent.putExtra(Constans.USER_MSG_EDT, Constans.PROJECT_EXPERIENCE);
                        mContext.startActivity(projectExperienceIntent);
                        break;
                    case 10:
                        Intent selfEvaluationIntent = new Intent(mContext, UserMessagerEdtActivity.class);
                        selfEvaluationIntent.putExtra(Constans.USER_MSG_EDT, Constans.SELF_EVALUATION);
                        mContext.startActivity(selfEvaluationIntent);
                        break;
                }

            }
        });
        //隐藏最后条目的分割线，因为adapter加入头部，所以真正开始位置是1
        if (helper.getAdapterPosition() == mData.size()) {
            helper.setVisible(R.id.view_item_fragment_user_writer_divide, false);
        }
    }
}
